# Copyright 2008-2015 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# This file is part of the gdb testsuite.

# PR server/17457
# Test aarch64 floating point registers q0, q1, v0, v1, fpsr, fpcr

if {![is_aarch64_target]} {
    verbose "Skipping ${gdb_test_file_name}."
    return
}

standard_testfile
if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
    return -1
}

if ![runto_main] {
    untested "could not run to main"
    return -1
}

set endianness "little"
set test "show endian"
gdb_test_multiple $test $test {
    -re "(.* )(big|little)( endian.*)$gdb_prompt $" {
        set endianness $expect_out(2,string)
        pass "endianness"
    }
}

gdb_test "break ${srcfile}:[gdb_get_line_number "return"]" \
    "Breakpoint $decimal at 0x\[0-9a-fA-F\]+: file .*${srcfile}.*\\\." \
    "set the breakpoint after setting the fp registers"

gdb_test "continue" \
    "Continuing.*Breakpoint $decimal.*" \
    "continue until breakpoint"

if {$endianness == "little"} {
    set reg_value0 "0x1f1e1d1c1b1a19181716151413121110"
    set reg_value1 "0x2f2e2d2c2b2a29282726252423222120"
} else {
    set reg_value0 "0x101112131415161718191a1b1c1d1e1f"
    set reg_value1 "0x202122232425262728292a2b2c2d2e2f"
}

gdb_test "info registers q0" \
    "q0.*{u = $reg_value0, s = $reg_value0.*" \
    "check register q0 value"

gdb_test "info registers q1" \
    "q1.*{u = $reg_value1, s = $reg_value1.*" \
    "check register q1 value"

gdb_test "info registers v0" \
    "v0.*$reg_value0}}}" \
    "check register v0 value"

gdb_test "info registers v1" \
    "v1.*$reg_value1}}}" \
    "check register v1 value"

gdb_test "info registers fpsr" \
    "fpsr.*0x\[0-9a-fA-F\].*" \
    "check register fpsr value"

gdb_test "info registers fpcr" \
    "fpcr.*0x\[0-9a-fA-F\].*" \
    "check register fpcr value"

